<template>
  <div class="content">
    <!-- <div class="banner px-30 mt-10">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item>
          <img src="../assets/images/banner.png" alt="" />
        </van-swipe-item>
      </van-swipe>
    </div> -->
    <div class="list_box">
      <van-list
        :immediate-check="false"
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getNewsList"
      >
        <div
          class="item flex justify-between flex-items-center box-border"
          v-for="(item, index) in newsList"
          :key="item.id + index"
          @click="gotoDetail(item.id)"
        >
          <div class="item_l flex-grow-1 flex flex-col justify-between">
            <div class="title box-border">{{ item.title }}</div>
            <div class="info flex">
              <div class="info_l flex flex-items-center">
                <img src="../assets/images/send_time_icon.png" alt="" />
                <span>{{ item.updateTime.split(" ")[0] }}</span>
              </div>
              <div class="info_r flex flex-items-center">
                <img src="../assets/images/view_num_icon.png" alt="" />
                <span>{{ item.viewCount }}</span>
              </div>
            </div>
          </div>
          <div class="item_r flex justify-center flex-items-center" v-if="!!item.imgUrl">
            <img :src=" imgUrlConcat(item.imgUrl)" alt=""/>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
import { getNewsList } from "@/api/api";
export default {
  data() {
    return {
      pageSize: 10,
      pageNum: 1,
      loading: false,
      finished: false,
      newsList: [],
      totalData: "",
    };
  },
  computed: {
    imgUrlConcat() {
      return (url) => {
        return process.env.VUE_APP_BASE_API + url;
      }
    }
  },
  created() {
    this.getNewsList();
  },
  methods: {
    async getNewsList() {
      let params = {
        status:'上线',
        pageSize: this.pageSize,
        pageNum: this.pageNum,
      };
      let { data } = await getNewsList(params);
      if (data.code == 200) {
        this.totalData = data.total;
        this.newsList = this.newsList.concat(data.rows);
        this.pageNum++;
        this.loading = false;
        if (this.newsList.length >= this.totalData) {
          this.finished = true;
        }
      }
    },
    gotoDetail(id) {
      this.$router.push({
        path: "/article-details",
        query: {
          id,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
  border-radius: 20px;
  img {
    width: 100%;
  }
}

.van-swipe {
  width: 100%;
  height: 100% !important;
}
.banner {
  width: 690px;
  height: 300px;
}
.list_box {
  .item {
    padding: 30px 30px 30px 20px;
    margin: 30px auto;
    width: 690px;
    height: 220px;
    background: #ffffff;
    box-shadow: 0px 0px 16px 1px rgba(0, 0, 0, 0.1);
    border-radius: 20px 20px 20px 20px;
    border: 1px solid rgba(0, 0, 0, 0);

    .item_l {
      height: 100%;
      padding-right: 20px;
      .title {
        padding-left: 20px;
        font-weight: 400;
        font-size: 32px;
        color: #333333;
        line-height: 48px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .info {
        width: 100%;
        .info_r {
          img {
            margin-left: 113px;
          }
        }
        img {
          width: 44px;
          height: 44px;
        }
        span {
          font-weight: 400;
          font-size: 24px;
          color: #666666;
        }
      }
    }
    .item_r {
      img {
        width: 160px;
        height: 160px;
        object-fit: cover;
      }
    }
  }
}
</style>
